package com.guofen.controller.shlj;

import com.guofen.pojo.ShljAbnormalGarbage;
import com.guofen.pojo.ShljBlockageCleaning;
import com.guofen.service.shlj.BlockageCleaningService;
import com.guofen.util.result.Result;
import com.guofen.util.result.ResultGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@RequestMapping("/shlj/blockageCleaning")
@Controller
@Api(tags = "BlockageCleaningController", description = "堵塞清掏记录表")
public class BlockageCleaningController {

    @Autowired
    private BlockageCleaningService service;

    @ApiOperation("添加记录")
    @RequestMapping(value = "/addForm",method = RequestMethod.POST)
    @ResponseBody
    public Result addForm(@ApiParam(name="time",value="时间",required=true) @RequestParam String time,
                          @ApiParam(name="blockage_position",value="堵塞部位",required=true) @RequestParam String blockage_position,
                          @ApiParam(name="cleaning_person",value="清掏人员",required=true) @RequestParam String cleaning_person,
                          @ApiParam(name="recording_person",value="记录人员",required=true) @RequestParam String recording_person,
                          @ApiParam(name="remarks",value="备注",required=false) @RequestParam String remarks){
        if (service.addForm(time, blockage_position, cleaning_person, recording_person, remarks))
            return ResultGenerator.genSuccessResult();
        else
            return ResultGenerator.genFailResult("保存失败");
    }

    @ApiOperation("删除记录")
    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    @ResponseBody
    public Result delete(@ApiParam(name="id",value="ID",required=true) @RequestParam Integer id) {
        return ResultGenerator.genSuccessResult(service.delete(id));
    }

    @ApiOperation("修改记录")
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @ResponseBody
    public Result update(@ApiParam(name="id",value="ID",required=true) @RequestParam Integer id,
                         @ApiParam(name="blockage_position",value="堵塞部位",required=true) @RequestParam String blockage_position,
                         @ApiParam(name="cleaning_person",value="清掏人员",required=true) @RequestParam String cleaning_person,
                         @ApiParam(name="recording_person",value="记录人员",required=true) @RequestParam String recording_person,
                         @ApiParam(name="remarks",value="备注",required=false) @RequestParam String remarks) {
        ShljBlockageCleaning record = new ShljBlockageCleaning();
        record.setId(id);
        record.setBlockagePosition(blockage_position);
        record.setCleaningPerson(cleaning_person);
        record.setRecordingPerson(recording_person);
        record.setRemarks(remarks);
        return ResultGenerator.genSuccessResult(service.update(record));
    }

    @ApiOperation("查找记录")
    @RequestMapping(value = "/select",method = RequestMethod.POST)
    @ResponseBody
    public Result select(@ApiParam(name="pageSize",value="页容量",required=true) @RequestParam Integer pageSize,
                         @ApiParam(name="currentPage",value="当前页",required=true) @RequestParam Integer currentPage,
                         @ApiParam(name="startTime",value="开始时间") Long startTime,
                         @ApiParam(name="endTime",value="截止时间") Long endTime) {
        if (startTime == null || endTime == null)
            return ResultGenerator.genSuccessResult(service.get(pageSize, currentPage));
        else
            return ResultGenerator.genSuccessResult(service.getByTime(pageSize, currentPage, startTime, endTime));
    }

    @ApiOperation("查询记录")
    @RequestMapping(value = "/findForm", method = RequestMethod.GET)
    @ResponseBody
    public Result findForm(){
        if (service.findForm() != null)
            return ResultGenerator.genSuccessResult(service.findForm());
        else
            return ResultGenerator.genFailResult("暂无记录");
    }
}
